<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>demo03</title>
</head>
<body>
  <!-- 闭包 与 面向对象设计 -->
  <script>
    // 闭包
    var extent = function() {
      var value = 0;
      return  {
        call: function() {
          return ++value;
        }
      }
    }
    var extent = extent()
    console.log(extent.call())
    console.log(extent.call())
    console.log(extent.call())

    // 面向对象
    var extent2 = {
      value: 0,
      call: function() {
        return ++this.value;
      }
    }

    console.log(extent2.call())
    console.log(extent2.call())
    console.log(extent2.call())

  </script>
</body>
</html>